package com.example.maybeaccount.Mode;

import android.content.Context;

import com.example.maybeaccount.MainActivity;
import com.example.maybeaccount.R;
import com.example.maybeaccount.multiselectpopupwindows.model.Search;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
 * 分类管理，组织一二级分类的关系，主要用于图表的一二级显示
 */
public class ClassifyManager {
    /**
     * <一级分类，二级分类表>
     */
    private HashMap<String, ArrayList<String>> classMap = new HashMap<>();
    private HashMap<String, ArrayList<String>> classInMap = new HashMap<>();
    private Context context;
    public ClassifyManager(Context context){
        this.context = context;
    }

    public void initFromXML(){
        String [] class1List = context.getResources().getStringArray(R.array.menu1);
        ArrayList <String> [] tempChildList = new ArrayList[class1List.length];

        String [] test = context.getResources().getStringArray(R.array.menu2_shopping);

        for(int i = 0;i < class1List.length;i ++){
            tempChildList[i] = new ArrayList<>();
        }

        tempChildList[0].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_shopping)));

        tempChildList[1].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_transport)));

        tempChildList[2].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_food)));

        tempChildList[3].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_play)));

        for(int i = 0;i < class1List.length;i ++){
            classMap.put(class1List[i],tempChildList[i]);
        }
    }

    public void initInFromXML(){
        String [] class1List = context.getResources().getStringArray(R.array.menu_income);
        /*
        ArrayList <String> [] tempChildList = new ArrayList[class1List.length];

        String [] test = context.getResources().getStringArray(R.array.menu2_shopping);

        for(int i = 0;i < class1List.length;i ++){
            tempChildList[i] = new ArrayList<>();
        }

        tempChildList[0].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_shopping)));

        tempChildList[1].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_transport)));

        tempChildList[2].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_food)));

        tempChildList[3].addAll( Arrays.asList(context.getResources().getStringArray(R.array.menu2_play)));
        */
        for(int i = 0;i < class1List.length;i ++){
            classInMap.put(class1List[i],null);
        }
    }

    public ArrayList<String> getChildOfClass1(String className){
        ArrayList<String> childList = new ArrayList<>();
        if(classMap.containsKey(className)){
            return classMap.get(className);
        }else{
            return childList;
        }
    }

    public ArrayList<Search> getClass1SearchList(){
        ArrayList<Search> class1List = new ArrayList<>();
        int i = 0;
        for(String key:classMap.keySet()){
            if(!key.equals("自定义")){
                class1List.add(new Search(key,true,i+""));
            }
            i++;
        }
        return class1List;
    }

    public ArrayList<Search> getClass1InSearchList(){
        ArrayList<Search> class1List = new ArrayList<>();
        int i = 0;
        for(String key:classInMap.keySet()){
            if(!key.equals("自定义")){
                class1List.add(new Search(key,true,i+""));
            }
            i++;
        }
        return class1List;
    }



}
